
const ws = new WebSocket('ws://127.0.0.1:9000/');

ws.onopen = function () {
    ws.send('大家好');
}

ws.onmessage = function(event){
    
    var chatroot = document.querySelector('#chatroot');

    chatroot.innerHTML += '<br/>' + event.data;
}

ws.onclose = function () {
    alert('Closed');
}

ws.onerror = function (error) {
    alert('error: '+error);
}